package net.zcscloud.zhuohcun.zeco.controller;

import net.zcscloud.zhuohcun.zeco.common.controller.LogicController;
import net.zcscloud.zhuohcun.zeco.dao.CameraDao;
import net.zcscloud.zhuohcun.zeco.entity.Camera;
import net.zcscloud.zhuohcun.zeco.entity.Usertoken;
import net.zcscloud.zhuohcun.zeco.service.*;
import io.swagger.annotations.Api;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Api(tags = "摄像机实体的控制器")
@RestController
@RequestMapping("/api/camera")
@CrossOrigin(origins = "*")
public class CameraController extends LogicController<CameraService, CameraDao,Camera,Long> {
    @Autowired
    private CameraService cameraService;
    @Autowired
    private UserService userService;

    public CameraController(@Autowired CameraService service){
        super(service);
    }


    @PostMapping("/geturl")
    public String geturl(@RequestBody Usertoken usertoken) {
        if(userService.verifyToken(usertoken.getToken())=="0"){
            return cameraService.geturl(usertoken.getGhid());
        }else {
            return null;
        }
    }

    @PostMapping("/shot")
    public String shot(@RequestBody Shotreq shotreq) throws IOException {
        if(userService.verifyToken(shotreq.getToken())=="0"){
            return cameraService.shot(shotreq.getGhid(),shotreq.getQuality());
        }else {
            return null;
        }
    }
}
@Getter
class Shotreq {
    String ghid;
    String token;
    String quality;
}
